//
//  LWSportTracking.m
//  LWmyTracking
//
//  Created by mac on 17/1/16.
//  Copyright © 2017年 ITLIN. All rights reserved.
//

#import "LWSportTracking.h"
@interface LWSportTracking()

//运动 包含所有折线数组
@property(strong,nonatomic)NSMutableArray<LWSportTrackingLine *> *sportTrackingLines;

//记录起点位置
@property(strong,nonatomic)CLLocation *startLocal;

@end
@implementation LWSportTracking

- (instancetype)initWithSportType:(LWSportType)sportType
{
    if(self = [super init])
    {
        self.sportType = sportType;
        //记得初始化这个可变数组
        self.sportTrackingLines = [NSMutableArray array];
    }
    return self;
}

//写 img的 get 方法 -> 根据不同的运动类型获取不同的图片
- (UIImage *)sportTypeImg
{
    UIImage *image;
    switch (self.sportType) {
        case LWSportTypeWalk:
            image = [UIImage imageNamed:@"map_annotation_walk"];
            break;
        case LWSportTypeRun:
            image = [UIImage imageNamed:@"map_annotation_run"];
            break;
        case LWSportTypeBike:
            image = [UIImage imageNamed:@"map_annotation_bike"];
            break;
        default:
            break;
    }
    return image;
}


// 给一个 location --> 返回一个 覆盖物-->LWSportPolyLine
- (LWSportPolyLine *)appendPolyLineWithLocation:(CLLocation *)location
{
    
    //性能优化-->速度 小于等于0 的时候不要进行划线
#warning --->在室内的时候,有可能会出现速度为负值的时候, 如果人停了,速度就是为 0
    
    if(location.speed <= 0)
    {
        return nil;
    }
    
    if(self.startLocal == nil)
    {
        self.startLocal = location;
        return nil;
    }
    //创建包装过一次的折线模型
    LWSportTrackingLine *trackLine = [[LWSportTrackingLine alloc] initWithStartLocation:self.startLocal andEndLocation:location];
    //给自己的数组添加上去
    [self.sportTrackingLines addObject:trackLine];
    //在把当前位置赋值为 startLocation
    self.startLocal = location;
    
    return trackLine.polyLine;
    
}

@end
